#include "Renderer.h"
//-----------------------------------------------
Renderer::Renderer():
	m_pkD3D(new LPDIRECT3D9()),
	m_pkDevice(new LPDIRECT3DDEVICE9()){
		r=0;g=0;b=0;
	}

//-----------------------------------------------
Renderer::~Renderer(){
	(*m_pkDevice)->Release();
	m_pkDevice = NULL;
	(* m_pkD3D)->Release();
	m_pkD3D = NULL;
}
//-----------------------------------------------
bool Renderer::init(HWND hWnd){
	*m_pkD3D = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS d;
	ZeroMemory(&d, sizeof(d));
	d.Windowed = TRUE;
	d.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d.hDeviceWindow = hWnd;
	if( (*m_pkD3D)->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d, m_pkDevice) != D3D_OK )
		return false;
	return true;
}
//-----------------------------------------------
void Renderer::beginFrame(){
	// Limpio
	(*m_pkDevice)->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(r, g, b), 1.0f, 0);

	//codigo flashero
	if(r>=255)
		r=0;
	r+=3;
	if(g>=255)
		g=0;
	g+=12;
	if(b>=255)
		b=0;
	b+=25;
	//fin codigo flashero

	// Comienzo
	(*m_pkDevice)->BeginScene();
}
//-----------------------------------------------
void Renderer::endFrame(){
	// Termina 
	(*m_pkDevice)->EndScene();
	(*m_pkDevice)->Present(NULL, NULL, NULL, NULL);
	
}

//-----------------------------------------------